package com.itheima.zhaohang.livepalyonline;

import android.os.Handler;
import android.os.Looper;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.ImageView;

public class AskAserAvticity extends AppCompatActivity implements View.OnClickListener {

    private ImageView       mBack;
    private ImageView       mErroChengge;
    private CheckedTextView mTvtime;
    private ImageView       mShare;
    private ViewPager       mViewPager;
    private Handler mHandler = new Handler(Looper.getMainLooper());
    //计时器任务
    private int     time     = 0;
    private int     second   = 0;
    private int     minute   = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ask_aser_avticity);
        mBack = (ImageView) findViewById(R.id.imageback);

        mErroChengge = (ImageView) findViewById(R.id.errochengge);
        mTvtime = (CheckedTextView) findViewById(R.id.tv_time);
        mShare = (ImageView) findViewById(R.id.tv_share);
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mBack.setOnClickListener(this);
        mErroChengge.setOnClickListener(this);
        mTvtime.setOnClickListener(this);
        mShare.setOnClickListener(this);


        mTvtime.setText("00:00");

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {

                time++;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {


                        mTvtime.setText(getTimeText(time));
                    }
                });
            }
        }, 1000);

    }

    private String getTimeText(int time) {

        second = time % 60;
        minute = time / 60;
        if (minute > 99) {
            time = 0;
            return "00:00";
        }


        return null;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.imageback:
                finish();
                break;
            //错题
            case R.id.errochengge:

                break;
            //答题时间
            case R.id.tv_time:
                break;

            //分享
            case R.id.tv_share:

                break;
        }
    }
}
